package utils;

import java.util.List;

import newsEventSystem.Domain;
import newsEventSystem.News;
import newsEventSystem.NewsCenter;

public class NewsEventSystemUtils {
	
	private static NewsCenter newsCenter = NewsCenter.getInsance();
	
	public static String getDomains() {
		String text = "";
		List<Domain> domains = newsCenter.getDomains();
		for (Domain parent : domains) {
			if (parent.getParentName() == null) {
				text += parent.getDomainName() + ":";
				for (Domain subdomain : domains) {
					if (parent.getDomainName()
							.equals(subdomain.getParentName())) {
						text += subdomain.getDomainName() + " ";
					}
				}
				text += "\n";
			}
		}
		return text;
	}

	public static News getNewsByTitle(String title) {
		for (Domain d : newsCenter.getDomains()) {
			for (News n : d.getNewsList())
				if (n.getTitle().equals(title)) {
					return n;
				}
		}
		return null;
	}

	public static Domain getDomainByNews(News n) {
		for (Domain temp : newsCenter.getDomains())
			for (News stire : temp.getNewsList())
				if (stire.equals(n)) {
					return temp;
				}
		return null;
	}

}
